<!--  -->
<template>
  <div style="margin:30px;">
    <el-form :model="form" ref="form" label-width="120px">
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="文章标题">
            <el-input v-model="form.title"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="作者">
            <el-input v-model="form.author"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="摘要">
        <el-input type="textarea" v-model="form.desc"></el-input>
      </el-form-item>
      <el-form-item label="最热">
        <el-switch
          v-model="form.hot"
          active-color="#13ce66"
          inactive-color="#e5e5e5"
          active-value="0"
          inactive-value="1"
        ></el-switch>
      </el-form-item>

      <el-col :span="12">
        <img style="width:120px;height:40px;object-fit:contain" :src="form.cover" alt />
      </el-col>
      <el-col :span="4">
        <el-button v-if="form.cover" style="color:red" type="text" @click="removeCover">删除</el-button>
      </el-col>

      <!-- </el-form-item> -->
      <el-form-item label="文章显示封面">
        <el-switch
          v-model="form.coverShow"
          active-color="#13ce66"
          inactive-color="#e5e5e5"
          active-value="0"
          inactive-value="1"
        ></el-switch>
      </el-form-item>
      <el-form-item label="切换富文本类型">
        <el-row>
          <el-col :span="6">
            <el-radio-group @change="editorTypeChange" v-model="form.type">
              <el-radio label="0">富文本</el-radio>
              <el-radio label="1">markdown</el-radio>
            </el-radio-group>
          </el-col>
          <el-col :span="12">
            <span style="color: #E6A23C;margin-left:50px;">
              <i class="el-icon-warning"></i> 切换编辑器会清空内容,请谨慎操作.
            </span>
          </el-col>
        </el-row>
      </el-form-item>
      <Tinymce v-model="tinContent" ref="tin" @send="receive" uploadurl="http://www.bufantec.com/admin/xy/upload/uploadImg"></Tinymce>
      <!-- <el-button type="primary" @click="getTin">获取富文本内容</el-button>
      <el-button type="primary" @click="setTin">设置富文本内容</el-button> -->
      <el-button type="primary" @click="onSubmit">立即创建</el-button>
    </el-form>
  </div>
</template>

<script>
import Tinymce from "@/components/Tinymce/index";
import { detail,update } from "@/api/material/news";
export default {
  data() {
    return {
      id: "",
      tinContent: "",
      mdContent: "",
      form: {},
    };
  },
  components: {
    Tinymce,
  },
  computed: {},
  created() {
    this.id = this.$route.params.id;
    this.getNewsDetail();
  },
  mounted() {},
  methods: {
      removeCover(){},
       receive(e){
      this.form.cover= e;
    },
    editorTypeChange(){},
    getTin() {
      console.log(this.tinContent)
    },
    setTin() {
      this.$refs.tin.setContent(this.form.content1);
      console.log(this.tinContent)
    },
    getNewsDetail() {
      detail({ id: this.id }).then((res) => {
        console.log(res);
        this.form = res.data;
        this.setTin();
      });
    },
     onSubmit() {
      this.form.content1=this.tinContent;
      var submitObj = {
        xyNews: {
          ...this.form,
        },
      };
      update(submitObj).then((res) => {
        console.log(res);
        this.$router.push({ name: "xynews" });
      });
    },
  },
};
</script>

<style lang='scss' scoped >
</style>
